<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>枚举常量</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="language.enumerations.static-methods.html">« 枚举静态方法</a></li>
      <li style="float: right;"><a href="language.enumerations.traits.html">Trait »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="language.enumerations.html">枚举</a></li>
    <li>枚举常量</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="language.enumerations.constants" class="sect1">
  <h2 class="title">枚举常量</h2>

  <p class="para">
   仅管 enum 可以包括 public、private、protected 的常量，
   但由于它不支持继承，因此在实践中 private 和 protected 效果是相同的。
  </p>

  <p class="para">枚举常量可以引用枚举条目：</p>

  <div class="example-contents">
   <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />enum&nbsp;Size<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">Small</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">Medium</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">Large</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;const&nbsp;</span><span style="color: #0000BB">Huge&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">Large</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </div></div></div></body></html>